package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.AppBanner;
import com.addplus.townmall.server.api.model.town.expand.AppBannerExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商城banner Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-08-27
 */
public interface AppBannerMapper extends BaseAddMapper<AppBanner> {

    @Select("select IFNULL(max(sort)+1,1) as sort from app_banner where show_platform=#{show_platform} and show_location=#{show_location}")
    Integer selectMaxSort(@Param("show_platform") Integer show_platform, @Param("show_location") String show_location);


    @Select("SELECT\n" +
            " a.id,\n" +
            " a.`show_location`,\n" +
            " a.`name`,\n" +
            " a.img_path,\n" +
            " a.skip_obj,\n" +
            " a.`show_platform`,\n" +
            " a.`sort`,\n" +
            " a.`gmt_modified`,\n" +
            " r.skip_name,\n" +
            " r.skip_type,\n" +
            " r.skip_url,\n" +
            " r.skip_router_type,\n" +
            " r.wildcard_count \n" +
            "FROM\n" +
            " app_banner a\n" +
            " INNER JOIN town_skip_router r ON r.id = a.skip_router_id \n" +
            " AND a.is_delete = 0 \n" +
            "WHERE\n" +
            " a.show_platform = #{showPlatform} \n" +
            " AND a.show_location = #{showLocation} \n" +
            " AND a.is_delete = 0 \n" +
            "ORDER BY\n" +
            " a.sort ASC")
    List<AppBannerExpand> getAppBannerByPlatformLocation(@Param("showLocation") String showLocation, @Param("showPlatform") Integer showPlatform);

    @Select("SELECT\n" +
            " a.id,\n" +
            " a.`show_location`,\n" +
            " a.`name`,\n" +
            " a.img_path,\n" +
            " a.skip_obj,\n" +
            " a.`show_platform`,\n" +
            " a.`sort`,\n" +
            " a.`gmt_modified`,\n" +
            " r.skip_name,\n" +
            " r.skip_type,\n" +
            " r.skip_url,\n" +
            " r.skip_router_type,\n" +
            " r.wildcard_count \n" +
            "FROM\n" +
            " app_banner a\n" +
            " INNER JOIN town_skip_router r ON r.id = a.skip_router_id \n" +
            " AND a.is_delete = 0 \n" +
            "WHERE\n" +
            " a.show_platform = #{showPlatform} \n" +
            " AND a.show_location = #{showLocation} \n" +
            " AND a.is_delete = 0 \n" +
            "ORDER BY\n" +
            " a.sort ASC")
    List<AppBannerExpand> getAppBannerByPlatformLocationPage(@Param("page") Page page, @Param("showLocation") String showLocation, @Param("showPlatform") Integer showPlatform);
}
